import java.util.Scanner;

public class Test2 {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        // 注意 hasNext 和 hasNextLine 的区别
        while (in.hasNextInt()) { // 注意 while 处理多个 case
            int len = in.nextInt();
            in.nextLine();
            int[] nums = new int[len];
            int prev = -0x3f3f3f3f;
            int maxSum = -0x3f3f3f3f;
            for (int i = 0; i < len; i++) {
                nums[i] = in.nextInt();
                prev = Math.max(prev + nums[i], nums[i]);
                maxSum = Math.max(maxSum, prev);
            }
            System.out.println(maxSum);
        }
    }
}
